<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Admin.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<Pulog.Models.Category>>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">

    <h2>Category</h2>

    <table>
        <tr>
            <th></th>
            <th>
                categoryID
            </th>
            <th>
                categoryName
            </th>
            <th>
                categoryDesc
            </th>
            <th>
                categoryOrder
            </th>
            <th>
                categoryIcon
            </th>
            <th>
                categoryURL
            </th>
        </tr>

    <% foreach (var item in Model) { %>
    
        <tr>
            <td>
                <%= Html.ActionLink("Edit", "EditCategory", new { id=item.categoryID }) %> |
                <%--<%= Html.ActionLink("Delete", "DeleteCategory", new { id = item.categoryID })%>--%>
                <a id="DeletePost" href="javascript:DeleteCategory(<%=item.categoryID %>)">Delete</a>
            </td>
            <td>
                <%= Html.Encode(item.categoryID) %>
            </td>
            <td>
                <%= Html.Encode(item.categoryName) %>
            </td>
            <td>
                <%= Html.Encode(item.categoryDesc) %>
            </td>
            <td>
                <%= Html.Encode(item.categoryOrder) %>
            </td>
            <td>
                <%= Html.Encode(item.categoryIcon) %>
            </td>
            <td>
                <%= Html.Encode(item.categoryURL) %>
            </td>
        </tr>
    
    <% } %>

    </table>

    <p>
        <%= Html.ActionLink("Create New", "AddCategory") %>
    </p>

</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="head" runat="server">
    <script type="text/javascript">
        function DeleteCategory(id)
        {
            $.ajax({
                type: "POST",
                data: "id="+id,
                dataType: "json",
                url: "<%=ResolveUrl("~/Admin/DeleteCategory/") %>",
                success: function(){
                    alert('y');
                },
                eror: function() {
                    alert('err');
                },
                complete: function(){
                    alert("Complete");
                    window.location.reload();
                }
            });
        }
    </script>
</asp:Content>

